package com.cyzy.server.dao;

import com.cyzy.pojo.dto.StarDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StarDao {
    /**
     *查询是否有这个userId
     */
    @Select("SELECT user_id from star_card where type = #{type}")
    List<Integer> selectUserIdInStarCard(String type);

    /**
     * 根据userId查询是否收藏表里有收藏过这个帖子
     */
    @Select("SELECT card_id FROM star_card WHERE type = #{type} AND user_id = #{userId}")
    List<Integer> selectStarTypeCardById(Integer userId,String type);


    /**
     * 如果用户名不存在，就插入，一般用于首次收藏
     */
    @Insert("insert into star_card (type,user_id,card_id,is_star) values (#{type},#{userId},#{cardId},#{isStar})")
    void insertStarCard(StarDTO starDTO);


    /**
     * 如果用户名存在，则修改对应的收藏信息
     */
    @Update("update star_card set is_star = #{isStar} where type = #{type} and user_id = #{userId} and " +
            "card_id = #{cardId} ")
    void updateStarCard(StarDTO starDTO);

    /**
     * 根据用户id查询其收藏的帖子数
     */
    @Select("select count(*) from star_card where user_id = #{userId};")
    int getStars(Integer userId);


    /**
     * 根据用户id查询其收藏的招募帖子id
     */
    @Select("select card_id from star_card where type = \"recruit\" and user_id = #{id}")
    List<Integer> selectRecruitByUserId(Integer id);

    @Select("select card_id from star_card where type = \"Hunt\" and user_id = #{id}")
    List<Integer> selectHuntByUserId(Integer id);
}
